//Tue Jul 26 14:33:41 IST 2011
#include <stdio.h>

int compact (char *str, int begin)
{	

	int i, j, nextchar;

	for (i=begin; str[i]; i++) {
		while (str[i] == str[i+1])
			i++;

		if (str[i+1]) {
			nextchar = compact (str, i+1);
			for (j=begin+1; str[nextchar]; j++)
				str [j] = str[nextchar++];
			str [j] = '\0';
			return (begin);
		} else {
			str [begin +1] = '\0';

			printf ("%s\n", str);
			return (begin);
		}
	}
	return 0;
}




int main()
{
	char str[] = "aaaabcedfdsbasdbeascbacbacbcacbeaccebecacsaceba";

	int i, j, c;

	for (i=0; str[i]; i++) {
		for (j=i+1; str[j]; j++) {
			if (str[i] > str[j]) {
				c = str[i];
				str [i] = str [j];
				str [j] = c;
			}
		}
	}

	printf("%s\n", str);

	compact (str, 0);

	printf("%s", str);
	return 0;
}
//Tue Jul 26 15:16:56 IST 2011
